<template>
  <DaprPlusTable
    :table-title="$t('fsb.softwares.functionAuthLog.list')"
    :entity="entity"
    :grid-options="gridOptions"
    :form-options="formOptions"
    :query-api="crudApi.getPage"
    @update:grid-api="onGridApiUpdate"
  />
</template>

<script lang="ts" setup>
import type { ExtendedVxeGridApi, VxeGridProps } from '#/adapter/vxe-table';
import type { VbenFormProps } from '#/adapter/form';
import { DaprPlusTable } from '#/components/daprplus';
import { createCrudApi } from '#/api/daprplus';
import type { IOutDto, EntityInfo } from '#/utils/daprplus';
import { $t } from '#/locales';

const baseUrl = '/softwares/api/functionauthlog';
const crudApi = createCrudApi<never, FunctionAuthLogOutDto>(baseUrl);

const entity: EntityInfo = {
  code: 'FunctionAuthLog',
  display: $t('fsb.softwares.functionAuthLog.title'),
};

// 配置搜索表单
const formOptions: VbenFormProps = {
  collapsed: false,
  schema: [
    {
      component: 'Input',
      label: '功能名称',
      fieldName: 'functionName',
    },
    {
      component: 'Input',
      label: '用户名',
      fieldName: 'userName',
    },
    {
      component: 'Input',
      label: '昵称',
      fieldName: 'nickName',
    },
    {
      component: 'Input',
      label: '客户端IP',
      fieldName: 'clientIp',
    },
    {
      component: 'Input',
      label: '客户端名称',
      fieldName: 'clientName',
    },
    {
      component: 'VbenSelect',
      label: '访问结果',
      fieldName: 'isSuccess',
      componentProps: {
        options: [
          { label: '成功', value: true },
          { label: '失败', value: false },
        ],
      },
    },
  ],
  showCollapseButton: true,
  submitOnChange: true,
};

// 扩展配置
const gridOptions: VxeGridProps<FunctionAuthLogOutDto> = {
  columns: [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '编号',
      sortable: true,
      width: 130,
    },
    {
      field: 'functionName',
      title: '功能名称',
      sortable: true,
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'userName',
      title: '用户名',
      sortable: true,
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'nickName',
      title: '昵称',
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'clientIp',
      title: '客户端IP',
      align: 'left',
      width: 130,
    },
    {
      field: 'clientName',
      title: '客户端名称',
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'isSuccess',
      title: '访问结果',
      width: 90,
      formatter: ({ cellValue }) => (cellValue ? '成功' : '失败'),
    },
    {
      field: 'createdTime',
      title: '创建时间',
      formatter: 'formatDateTime',
      width: 150,
    },
  ],
};

let gridApi: ExtendedVxeGridApi;

function onGridApiUpdate(api: ExtendedVxeGridApi) {
  gridApi = api;
}

export interface FunctionAuthLogOutDto extends IOutDto {
  functionName?: string;
  userName?: string;
  nickName?: string;
  clientIp?: string;
  clientName?: string;
  isSuccess?: boolean;
  createdTime?: Date;
}
</script>

<style scoped></style>
